<%--
  Created by IntelliJ IDEA.
  User: 47
  Date: 2020/12/4
  Time: 10:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.sjsq.po.User"%>
<%@ page import="com.sjsq.dao.impl.UserDao"%>
<%@ page import="com.sjsq.dao.impl.UserDaoImpl"%>
<%@ page import="com.sjsq.service.impl.UserService" %>
<%@ page import="com.sjsq.service.impl.UserServiceImpl" %>
<%@ page import="java.util.List" %>
<%
    // 获取绝对路径路径 ,开发项目一定要使用绝对路径，不然肯定出错
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort() + path + "/";
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="<%=basePath %>" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户登录</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        h4{
            text-align: center;color: red;
        }
        body{
            background-color: antiquewhite;
        }
    </style>
</head>
<body>
<h1>现存图书列表</h1>
<hr>
<h4>---装饰中---</h4>
<%
    // 设置接收的编码为UTF-8
    request.setCharacterEncoding("utf-8");
    User user = new User();
    UserDao dao = (UserDao) new UserDaoImpl();
    String name = request.getParameter("name");
    String password=request.getParameter("password");

    user.setName(name);
    user.setPassword(password);

    User us=dao.login(user);

    // 把数据库里面的User获取出来
    UserService service = new UserServiceImpl();
    List<User> list = service.selectUser(user);
    for(int i=0;i<list.size();i++){
        user = list.get(i);
    }


    System.out.println("显示用户信息：");
    System.out.println(user);

    session.setAttribute("user",user);
    if(us != null){
        response.sendRedirect("book.jsp");
    }else{
        response.sendRedirect("fail.jsp");
    }
%>
</body>
</html>